import request from '@/utils/request';
import { baseurl } from './baseurl';
import { isAnte, hasIsSw, isBinhai, isZhongZheng, hasCompany, isZhengda, isKean, isCeshi, isXinchengJs } from '../utils/utils';
export interface addTypeParams {
  title: string;
  level: string;
  num: string;
  pid: string;
}
export async function addType(params: addTypeParams) {
  const data = new FormData();
  data.append('level', params.level);
  data.append('title', params.title);
  data.append('num', params.num);
  data.append('pid', params.pid);
  return request(`${baseurl}index/index/add_type`, {
    method: 'POST',
    data,
  });
}

export async function getType() {
  /* 单位结构获取部门 */
  const data = new FormData();
  const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const student_type = userinfo.student_type ? userinfo.student_type.split(',') : ['', '', ''];
  const Super = userinfo.super;
  data.append('super', Super);
  data.append('level1', !student_type[0] || student_type[0] === 'null' ? '' : student_type[0]);
  data.append('level2', !student_type[1] || student_type[1] === 'null' ? '' : student_type[1]);
  data.append('level3', !student_type[2] || student_type[2] === 'null' ? '' : student_type[2]);
  return request(`${baseurl}index/index/type`, {
    method: 'POST',
    data,
  });
}

export interface changeTypeParams {
  id: string;
  title: string;
  num: string;
  level: string;
  pid: string;
}
export async function changeType(params: changeTypeParams) {
  /* 单位结构改变部门 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('type', '1');
  data.append('title', params.title);
  data.append('num', params.num);
  data.append('level', params.level);
  data.append('pid', params.pid);

  return request(`${baseurl}index/index/up_type`, {
    method: 'POST',
    data,
  });
}

export interface deleteTypeParams {
  id: string;
}
export async function deleteType(params: deleteTypeParams) {
  /* 单位结构删除部门 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('type', '2');
  return request(`${baseurl}index/index/up_type`, {
    method: 'POST',
    data,
  });
}

export interface getPositionParams {
  type: string;
  name: string;
  page: string;
}
export async function getPositon(params: getPositionParams) {
  /* 获取职务岗位 */
  const data = new FormData();
  data.append('type', params.type);
  data.append('name', params.name);
  data.append('page', params.page);
  return request(`${baseurl}index/index/duty`, {
    method: 'POST',
    data,
  });
}

export interface addPositionParams {
  type: string;
  name: string;
}
export async function addPosition(params: addPositionParams) {
  /* 职务岗位增加 */
  const data = new FormData();
  data.append('type', params.type);
  data.append('name', params.name);
  return request(`${baseurl}index/index/add_duty`, {
    method: 'POST',
    data,
  });
}

export interface editPositionParams {
  type: string;
  name: string;
  id: string;
}
export async function editPosition(params: editPositionParams) {
  /* 编辑职务岗位 */
  const data = new FormData();
  data.append('type', params.type);
  data.append('name', params.name);
  data.append('id', params.id);
  data.append('types', '1');
  return request(`${baseurl}index/index/up_duty`, {
    method: 'POST',
    data,
  });
}

export interface deletePositionParams {
  id: string;
}
export async function deletePosition(params: deletePositionParams) {
  /* 删除职务岗位 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('types', '2');
  return request(`${baseurl}index/index/up_duty`, {
    method: 'POST',
    data,
  });
}

export interface checkRepeatParams {
  id_number: string;
}
export async function checkRepeat(params: checkRepeatParams) {
  /* 检查考号重复 */
  const data = new FormData();
  data.append('id_number', params.id_number);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/examine_id`, {
    method: 'POST',
    data,
  });
}

export interface addPersonParams {
  id_number: string;
  name: string;
  password: string;
  type: string;
  student_type: string;
  sexy: string;
  duty: string;
  phone: string;
  subject: string;
  exam_date: string;
  company: string;
  invoice_img: any;
  invoice: string;
  forbidden: string;
  classes: string;
  photo: any; id_card_front: any; id_card_back: any;diploma: any; family_register: any;
}
export async function addPerson(params: addPersonParams) {
  /* 添加用户 */
  const data = new FormData();
  data.append('id_number', params.id_number);
  data.append('name', params.name);
  data.append('password', params.password);
  data.append('type', params.type);
  data.append('student_type', params.student_type);
  data.append('sexy', params.sexy);
  data.append('duty', params.duty);
  data.append('phone', params.phone);
  data.append('subject', params.subject);

  if (hasCompany()) {
    data.append('company', params.company);
  }
 
  if(isXinchengJs()){
    data.append('photo', params.photo);
    data.append('id_card_front', params.id_card_front);
    data.append('id_card_back', params.id_card_back);
    data.append('phdiplomaoto', params.diploma);
    data.append('family_register', params.family_register);
  }
  if (!isAnte()) {
    data.append('exam_date', params.exam_date);
  }
  if (isAnte()) {
    data.append('invoice_img', params.invoice_img);
    data.append('invoice', params.invoice);
  }
  if (isZhongZheng()) {
    data.append('invoice', params.invoice);
  }
  if (params.forbidden) {
    data.append('forbidden', params.forbidden);
  }
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/add_member`, {
    method: 'POST',
    data,
  });
}

export interface editPersonParams {
  id_number: string;
  name: string;
  password: string;
  type: string;
  student_type: string;
  sexy: string;
  duty: string;
  phone: string;
  subject: string;
  id: string;
  integral: string;
  exam_date: string;
  company: string;
  invoice_img: any;
  invoice: string;
  idcard: string;
  save: any;
  year:any;
  month:any;
  photo: any; id_card_front: any; id_card_back: any;diploma: any; family_register: any;
  classes:any;
  
}
export async function editPerson(params: editPersonParams) {
  /* 修改用户 */
  const data = new FormData();
  data.append('id_number', params.id_number);
  data.append('name', params.name);
  if (params.password) {
    data.append('password', params.password);
  }
  data.append('type', params.type);
  data.append('student_type', params.student_type);
  data.append('sexy', params.sexy);
  data.append('duty', params.duty);
  data.append('phone', params.phone);
  data.append('subject', params.subject);
  data.append('id', params.id);
  data.append('integral', params.integral);

  if (hasCompany()) {
    data.append('company', params.company);
  }
  if (!isAnte()) {
    data.append('exam_date', params.exam_date);
  }
  if(isXinchengJs()){
    data.append('photo', params.photo);
    data.append('id_card_front', params.id_card_front);
    data.append('id_card_back', params.id_card_back);
    data.append('phdiplomaoto', params.diploma);
    data.append('family_register', params.family_register);
  }
  if (isAnte()) {
    data.append('invoice_img', params.invoice_img);
    data.append('invoice', params.invoice);
  }
  if (isZhongZheng()) {
    data.append('invoice', params.invoice);
  }
  if (isZhongZheng() && params.idcard) {
    data.append('idcard', params.idcard);
  }
  if(isKean()){
    data.append('year', params.year);
    data.append('month', params.month);

  }
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/up_member`, {
    method: 'POST',
    data,
  });
}

export async function editRemark(params: any) {
  /* 修改备注  中正 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('remark', params.remark);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/up_member`, {
    method: 'POST',
    data,
  });
}

export async function deletePerson(params: any) {
  /* 删除用户 */
  const data = new FormData();
  data.append('id', params.id);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/del_member`, {
    method: 'POST',
    data,
  });
}

export interface getPersonParams {
  page: string;
  start_date: string;
  end_date: string;
  type: string;
  name: string;
  role: any;
  student_type: any;
  company: string;
  idcard: string;
  studenttype: string;
  exam_date:string;
  exam_dates:string;
  classes:string;
}
export async function getPerson(params: getPersonParams) {
  /* 获取用户 */
  const data = new FormData();
  const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const Super = userinfo.super;
  data.append('super', Super);
  data.append('page', params.page);
  data.append('start_date', params.start_date);
  data.append('end_date', params.end_date);
  data.append('type', params.type);
  data.append('name', params.name);
  data.append('role', params.role);
  data.append('student_type', params.student_type);
  data.append('classes', params.classes);
  if(isZhengda()){
    data.append('exam_date',params.exam_date);
    data.append('exam_dates',params.exam_dates);
  }
  if (isBinhai()||isZhengda()||isCeshi()) {
    data.append('company', params.company || '');
  }
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  if (isZhongZheng()) {
    data.append('idcard', params.idcard);
    data.append('studenttype', params.studenttype);
  }
  return request(`${baseurl}index/index/member`, {
    method: 'POST',
    data,
  });
}

export async function getAllPerson() {
  /* 获取全部用户 */
  const data = new FormData();
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/get_member`, {
    method: 'POST',
    data,
  });
}

export async function getPositonSelect() {
  /* 选择框用的职务 */
  const data = new FormData();
  data.append('type', '1');
  data.append('name', '');
  data.append('page', '');
  return request(`${baseurl}index/index/duty`, {
    method: 'POST',
    data,
  });
}

export async function disablePerson(params: any) {
  /* 禁用用户 */
  const data = new FormData();
  data.append('id', params.id);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/forbidden`, {
    method: 'POST',
    data,
  });
}

export interface getAuditParams {
  page: string;
  start_date: string;
  end_date: string;
  type: string;
  name: string;
  duty: any;
  power: any;
  baoming: any;
  company: any;
}
export async function getAudit(params: getAuditParams) {
  /* 获取审核用户列表 */
  const data = new FormData();
  const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const Super = userinfo.super;
  data.append('super', Super);
  data.append('page', params.page);
  data.append('start_date', params.start_date);
  data.append('end_date', params.end_date);
  data.append('duty', params.duty);
  data.append('type', params.type);
  data.append('name', params.name);
  data.append('power', params.power);
  data.append('baoming', params.baoming);
  if (isBinhai()||isZhengda()) {
    data.append('company', params.company || '');
  }
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  if (isZhongZheng()) {
    /* 中正调用新接口获取已完成用户 */
    if (params.baoming === '1')
      return request(`${baseurl}index/index/audit`, {
        method: 'POST',
        data,
      });
    return request(`${baseurl}index/index/ok_list`, {
      method: 'POST',
      data,
    });
  }
  return request(`${baseurl}index/index/audit`, {
    method: 'POST',
    data,
  });
}

export async function getOverdueUsers(params: getAuditParams) {
  /* 获取超期用户列表 中正 */
  const data = new FormData();
  const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const Super = userinfo.super;
  data.append('super', Super);
  data.append('page', params.page);
  data.append('start_date', params.start_date);
  data.append('end_date', params.end_date);
  data.append('duty', params.duty);
  data.append('type', params.type);
  data.append('name', params.name);
  data.append('power', params.power);
  data.append('baoming', params.baoming);
  if (isBinhai()) {
    data.append('company', params.company || '');
  }
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/audit`, {
    method: 'POST',
    data,
  });
}

export async function auditPerson(params: any) {
  /* 审核用户 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('student_type', params.student_type);
  data.append('uid', params.uid);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/ok`, {
    method: 'POST',
    data,
  });
}

export async function addAuthority(params: any) {
  /* 增加权限角色 */
  const data = new FormData();
  data.append('name', params.name);
  data.append('power', params.power);
  return request(`${baseurl}index/index/power`, {
    method: 'POST',
    data,
  });
}

export async function getAuthority(params: any) {
  /* 获取权限角色 */
  const data = new FormData();
  data.append('name', params.name);
  return request(`${baseurl}index/index/show_power`, {
    method: 'POST',
    data,
  });
}

export async function editAuthority(params: any) {
  /* 获取权限角色 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('type', '1');
  data.append('name', params.name);
  data.append('power', params.power);
  return request(`${baseurl}index/index/up_power`, {
    method: 'POST',
    data,
  });
}

export async function deleteAuthority(params: any) {
  /* 获取权限角色 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('type', '2');
  return request(`${baseurl}index/index/up_power`, {
    method: 'POST',
    data,
  });
}

export async function uploadPerson(params: any) {
  /* 批量上传 */
  const data = new FormData();
  data.append('doc', params.file);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/to_lead`, {
    method: 'POST',
    data,
  });
}
export async function uploadPersonForbidden(params: any) {
  /* 批量禁用 */
  const data = new FormData();
  data.append('doc', params.file);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/to_forbidden`, {
    method: 'POST',
    data,
  });
}
export async function uploadPersonAudit(params: any) {
  /* 审核批量上传（安特） */
  const data = new FormData();
  data.append('doc', params.file);
  return request(`${baseurl}index/index/to_leads`, {
    method: 'POST',
    data,
  });
}
export async function uploadExamTime(params: any) {
  /* 批量上传考试时间 */
  const data = new FormData();
  data.append('doc', params.file);
  return request(`${baseurl}index/index/up_exam_time`, {
    method: 'POST',
    data,
  });
}
export interface editStudentInfoParams {
  name: string;
  password: string;
  sexy: string;
  phone: string;
  birthday: string;
  work_time: string;
  education: string;
  id_number: string;
  id: string;
}
export async function editStudentInfo(params: editStudentInfoParams) {
  /* 学生端修改学生信息 */
  const data = new FormData();
  data.append('name', params.name);
  data.append('password', params.password);
  data.append('id_number', params.id_number);
  data.append('sexy', params.sexy);
  data.append('phone', params.phone);
  data.append('birthday', params.birthday);
  data.append('work_time', params.work_time);
  data.append('education', params.education);
  data.append('id', params.id);
  const is_sw = JSON.parse(localStorage.getItem('userinfo') || '{}').is_sw;
  if (hasIsSw()) {
    data.append('is_sw', is_sw);
  }
  return request(`${baseurl}index/index/up_member`, {
    method: 'POST',
    data,
  });
}

export interface downloadExcelWrongStudentsParams {
  id_number: any;
  id_numbers: any;
  id_numberss: any;
  id_numbersss: any;

  uid: any;
}
export async function downloadExcelWrongStudents(params: downloadExcelWrongStudentsParams) {
  /* 下载上传错误的学生列表 */
  return request(`${baseurl}index/index/derive_repetitions`, {
    method: 'POST',
    data: {
      id_number: params.id_number,
      id_numbers: params.id_numbers,
      id_numberss: params.id_numberss,
      id_numbersss: params.id_numbersss,

      uid: params.uid,
    },
  });
}
export async function justUpload(params: any) {
  /* 直接导入学生信息 */
  let is_sw = 0;
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      is_sw=1;
    } else {
      is_sw=2;
    }
  }
  let data = { id_numbersss: params.id_numbersss,is_sw}
  if (!hasIsSw()) {
   delete data.is_sw
  }
  return request(`${baseurl}index/index/to_id_member`, {
    method: 'POST',
    data
  });
}

export async function coverPeople(params: any) {
  /* 覆盖学生信息 */
  let is_sw = 0;
  let data = {
    id_number: params.id_number,
    is_sw,
    classes:params.classes,
}
  if (!hasIsSw()) {
   delete data.is_sw
  }
  return request(`${baseurl}index/index/up_lead`, {
    method: 'POST',
    data
  });
}

export async function deleteBatchPerson(params: any) {
  /* 批量删除 */
  const data = new FormData();
  data.append('doc', params.doc);
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/to_delete`, {
    method: 'POST',
    data,
  });
}

export interface sendWeixinMessageParams {
  name: any;
  member: any;
  subjects: any;
  content: any;
}
export async function sendWeixinMessage(params: sendWeixinMessageParams) {
  /* 发送微信推送 */
  return request(`${baseurl}index/index/muban`, {
    method: 'POST',
    data: {
      member: params.member,
      name: params.name,
      subjects: params.subjects,
      content: params.content,
    },
  });
}

export async function uploadingSynthesize(params: any) {
  /* 上传导出学习时间列表 */
  const data = new FormData();
  data.append('doc', params.doc);
  return request(`${baseurl}index/index/uploading_synthesize`, {
    method: 'POST',
    data,
  });
}

export async function addPayPerson(params: addPersonParams) {
  /* 添加缴费用户 */
  const data = new FormData();
  data.append('id_number', params.id_number);
  data.append('name', params.name);
  data.append('password', params.password);
  data.append('type', params.type);
  data.append('student_type', params.student_type);
  data.append('sexy', params.sexy);
  data.append('duty', params.duty);
  data.append('phone', params.phone);
  data.append('subject', params.subject);
  if (hasCompany()) {
    data.append('company', params.company);
  }
  if (!isAnte()) {
    data.append('exam_date', params.exam_date);
  }
  data.append('invoice', params.invoice);
  if (params.forbidden) {
    data.append('forbidden', params.forbidden);
  }
  // if (hasIsSw()) {
  //   if (location.href.includes('tzPeoples')) {
  //     data.append('is_sw', '1');
  //   } else {
  //     data.append('is_sw', '2');
  //   }
  // }
  return request(`${baseurl}index/index/add_member_audit`, {
    method: 'POST',
    data,
  });
}
export interface getPayPersonParams {
  page: string;
  start_date: string;
  end_date: string;
  type: string;
  name: string;
  role: any;
  student_type: any;
  company: string;
  audit_status: string;
}
export async function getPayPerson(params: getPayPersonParams) {
  /* 获取缴费用户列表 */
  const data = new FormData();
  const userinfo = JSON.parse(localStorage.getItem('userinfo') || '{}');
  const Super = userinfo.super;
  data.append('super', Super);
  data.append('page', params.page);
  data.append('start_date', params.start_date);
  data.append('end_date', params.end_date);
  data.append('type', params.type);
  data.append('role', params.role);
  data.append('name', params.name);
  data.append('student_type', params.student_type);
  data.append('audit_status', params.audit_status);
  if (isBinhai()) {
    data.append('company', params.company || '');
  }
  if (hasIsSw()) {
    if (location.href.includes('tzPeoples')) {
      data.append('is_sw', '1');
    } else {
      data.append('is_sw', '2');
    }
  }
  return request(`${baseurl}index/index/member_audit`, {
    method: 'POST',
    data,
  });
}
export async function uploadPayPerson(params: any) {
  /* 批量上传缴费用户 */
  const data = new FormData();
  data.append('doc', params.file);
  return request(`${baseurl}index/index/to_lead_audit`, {
    method: 'POST',
    data,
  });
}

export async function auditPayPerson(params: any) {
  /* 审核缴费用户 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('audit_status', params.audit_status);
  // if (hasIsSw()) {
  //   if (location.href.includes('tzPeoples')) {
  //     data.append('is_sw', '1');
  //   } else {
  //     data.append('is_sw', '2');
  //   }
  // }
  return request(`${baseurl}index/index/audit_pay`, {
    method: 'POST',
    data,
  });
}

export async function checkRepeatIdCard(params: any) {
  /* 检查编号重复 */
  const data = new FormData();
  data.append('idcard', params.idcard);
  return request(`${baseurl}index/index/examine_idcard`, {
    method: 'POST',
    data,
  });
}
export async function checkExamineIdNumber(params: any) {
  /* 检查有没有两种平台 */
  const data = new FormData();
  data.append('id_number', params.id_number);
  return request(`${baseurl}index/index/examine_id_number`, {
    method: 'POST',
    data,
  });
}
export async function changeIsQuent(params: any) {
  /* 修改用户搜题 */
  const data = new FormData();
  data.append('id', params.id);
  data.append('is_quent', params.is_quent);

  return request(`${baseurl}index/index/up_member`, {
    method: 'POST',
    data,
  });
}
